
use "Dataset_Schneider_and_Bos.dta", clear 

// Standardization of scale scores. The scale scores are standardized relative 
// to the mean trait percentages of all traits and groups, and the standard 
// deviation therein. The mean and standard deviation for this calculation are
// themselves calculated by putting the 99 trait percentages for each of the
// 5 social groups below each other, and taking the mean and sd.


rename *, lower // variable names all to lower case

foreach var of varlist active-whiny {
	gen `var'_se = `var'
	rename `var' `var'_o
}

collapse (mean) *_o (sem) *_se , by(group2) // get trait percentages per social group

reshape long active adventurous affectionate aggressive ambitious analytical arrogant artistic assertive athletic beautiful bitter boastful burly caring cautious charismatic coarse cold commandrespect compassionate competitive complaining confident corrupt creative cute cynical daring decent deceptive dependent determined devious dictatorial dishonest dominant driven educated egotistical emotional ethical feminine fussy gentle getsthingsdone problemsolving goodwithnums gorgeous greedy gullible hardnosed hardworking honest hostile imaginative in_touch independent inspiring intelligent intuitive knowledgeable leader liar logical loving manipulative masculine moral motherly motivated muscular nagging objective organized physically_strong powerhungry powerful pretty quant quarrelsome rational really_cares rich rugged scheming self_interested selfish sensitive servile sleazy smart sneaky spineless stern strong strongwilled subordinates sympathetic talkative tough separate_feelings unemotional unprincipled uptight warm weak educated_a wellspoken whiny, i(group2) j(meanorse) string

xpose, clear v

drop if _varname=="group2" | _varname=="meanorse"

rename v1 o_women_us      // female
rename v2 o_women_us_se
rename v3 o_fempol_us     // female politician
rename v4 o_fempol_us_se 
drop   v5                 // female profesional
drop   v6
rename v7 o_men_us        // male 
rename v8 o_men_us_se
rename v9 o_malpol_us     // male politician
rename v10 o_malpol_us_se
drop v11                  // male profesional
drop v12
rename v13 o_allpol_us    // politician
rename v14 o_allpol_us_se


rename _varname english 
replace english="commands respect" if english=="commandrespect"
replace english="gets things done" if english=="getsthingsdone" 
replace english="good at problem solving" if english=="problemsolving" 
replace english="good with numbers" if english=="goodwithnums" 
replace english="hard nosed" if english=="hardnosed" 
replace english="hard working" if english=="hardworking" 
replace english="in touch with people" if english=="in_touch" 
replace english="power hungry" if english=="powerhungry" 
replace english="quantitatively skilled" if english=="quant" 
replace english="really cares about people like me" if english=="really_cares" 
replace english="self-interested" if english=="self_interested" 
replace english="strong willed" if english=="strongwilled" 
replace english="subordinates self to others" if english=="subordinates" 
replace english="unable to separate feelings from ideas" if english=="separate_feelings" 
replace english="well educated" if english=="educated_a" 
replace english="well spoken" if english=="wellspoken" 
 
drop if english=="athletic"
drop if english=="beautiful"
drop if english=="burly"
drop if english=="cute"
drop if english=="feminine"
drop if english=="gorgeous"
drop if english=="masculine"
drop if english=="muscular"
drop if english=="physically_strong"
drop if english=="pretty"
drop if english=="rich"

gen trait=""
replace trait= "abenteuerlu"	if english==	 "adventurous"
replace trait= "herzlich"		if english==	 "affectionate"
replace trait= "ambitionier"	if english==	 "ambitious"
replace trait= "künstlerisc"	if english==	 "artistic"
replace trait= "durchsetzun"	if english==	 "assertive"
replace trait= "fürsorglich"	if english==	 "caring"
replace trait= "vorsichtig"		if english==	 "cautious"
replace trait= "grob"			if english==	 "coarse"
replace trait= "kühl"			if english==	 "cold"
replace trait= "respekteinf"	if english==	 "commands respect"
replace trait= "selbstsiche"	if english==	 "confident"
replace trait= "kreativ"		if english==	 "creative"
replace trait= "zynisch"		if english==	 "cynical"
replace trait= "anständig"		if english==	 "decent"
replace trait= "unselbständ"	if english==	 "dependent"
replace trait= "entschlosse"	if english==	 "determined"
replace trait= "gebildet"		if english==	 "educated"
replace trait= "egoistisch"		if english==	 "egotistical"
replace trait= "einfühlsam"		if english==	 "gentle"
replace trait= "gutmitZahle"	if english==	 "good with numbers"
replace trait= "abgebrüht"		if english==	 "hard nosed"
replace trait= "bürgernah"		if english==	 "in touch with people"
replace trait= "inspirieren"	if english==	 "inspiring"
replace trait= "intelligent"	if english==	 "intelligent"
replace trait= "sachkundig"		if english==	 "knowledgeable"
replace trait= "führungsper"	if english==	 "leader"
replace trait= "lügner"			if english==	 "liar"
replace trait= "mütterlich"		if english==	 "motherly"
replace trait= "motiviert"		if english==	 "motivated"
replace trait= "nörgelend"		if english==	 "nagging"
replace trait= "objektiv"		if english==	 "objective"
replace trait= "organisiert"	if english==	 "organized"
replace trait= "machthungri"	if english==	 "power hungry"
replace trait= "mathematisc"	if english==	 "quantitatively skilled"
replace trait= "rational"		if english==	 "rational"
replace trait= "sorgensichu"	if english==	 "really cares about people like me"
replace trait= "robust"			if english==	 "rugged"
replace trait= "intrigant"		if english==	 "scheming"
replace trait= "eigennützig"	if english==	 "self-interested"
replace trait= "sensibel"		if english==	 "sensitive"
replace trait= "unterwürfig"	if english==	 "subordinates self to others"
replace trait= "klug"			if english==	 "smart"
replace trait= "hinterlisti"	if english==	 "sneaky"
replace trait= "streng"			if english==	 "stern"
replace trait= "willensstar"	if english==	 "strong willed"
replace trait= "aufopfernd"		if english==	 "servile"
replace trait= "taff"			if english==	 "tough"
replace trait= "warmherzig"		if english==	 "warm"
replace trait= "gutgebildet"	if english==	 "well educated"
replace trait= "weinerlich"		if english==	 "whiny"
replace trait= "aktiv"			if english==	 "active"
replace trait= "aggressiv"		if english==	 "aggressive"
replace trait= "analytisch"		if english==	 "analytical"
replace trait= "arrogant"		if english==	 "arrogant"
replace trait= "verbittert"		if english==	 "bitter"
replace trait= "überheblich"	if english==	 "boastful"
replace trait= "charismatis"	if english==	 "charismatic"
replace trait= "mitfühlend"		if english==	 "compassionate"
replace trait= "ehrgeizig"		if english==	 "competitive"
replace trait= "jammernd"		if english==	 "complaining"
replace trait= "korrupt"		if english==	 "corrupt"
replace trait= "wagemutig"		if english==	 "daring"
replace trait= "betrügerisc"	if english==	 "deceptive"
replace trait= "hinterhälti"	if english==	 "devious"
replace trait= "diktatorisc"	if english==	 "dictatorial"
replace trait= "unehrlich"		if english==	 "dishonest"
replace trait= "dominant"		if english==	 "dominant"
replace trait= "getrieben"		if english==	 "driven"
replace trait= "emotional"		if english==	 "emotional"
replace trait= "ethisch"		if english==	 "ethical"
replace trait= "kleinlich"		if english==	 "fussy"
replace trait= "tatkräftig"		if english==	 "gets things done"
replace trait= "problemlösu"	if english==	 "good at problem solving"
replace trait= "gierig"			if english==	 "greedy"
replace trait= "leichtgläub"	if english==	 "gullible"
replace trait= "fleißig"		if english==	 "hard working"
replace trait= "ehrlich"		if english==	 "honest"
replace trait= "feindselig"		if english==	 "hostile"
replace trait= "phantasievo"	if english==	 "imaginative"
replace trait= "unabhängig"		if english==	 "independent"
replace trait= "intuitiv"		if english==	 "intuitive"
replace trait= "logisch"		if english==	 "logical"
replace trait= "liebevoll"		if english==	 "loving"
replace trait= "manipulativ"	if english==	 "manipulative"
replace trait= "integer"		if english==	 "moral"
replace trait= "mächtig"		if english==	 "powerful"
replace trait= "streitsücht"	if english==	 "quarrelsome"
replace trait= "selbstsücht"	if english==	 "selfish"
replace trait= "schmierig"		if english==	 "sleazy"
replace trait= "rückgratlos"	if english==	 "spineless"
replace trait= "stark"			if english==	 "strong"
replace trait= "sympathisch"	if english==	 "sympathetic"
replace trait= "gesprächig"		if english==	 "talkative"
replace trait= "nichtinderl"	if english==	 "unable to separate feelings from ideas"
replace trait= "unemotional"	if english==	 "unemotional"
replace trait= "prinzipienl"	if english==	 "unprincipled"
replace trait= "verklemmt"		if english==	 "uptight"
replace trait= "schwach"		if english==	 "weak"
replace trait= "wortgewandt"	if english==	 "well spoken"

drop english
save "originalpercentages_US.dta", replace


* Scale scores

use "Dataset_Schneider_and_Bos.dta", clear 
do "Globals scales.do" 



rename *, lower // variable names all to lower case

rename  adventurous         abenteuerlu	  
rename  affectionate        herzlich	       
rename  ambitious           ambitionier	
rename  artistic            künstlerisc	
rename  assertive           durchsetzun	
rename  caring              fürsorglich	
rename  cautious            vorsichtig	   
rename  coarse              grob		     
rename  cold                kühl		    
rename  commandrespect      respekteinf	
rename  confident           selbstsiche	
rename  creative            kreativ		
rename  cynical             zynisch		
rename  decent              anständig	 
rename  dependent           unselbständ	
rename  determined          entschlosse	 
rename  educated            gebildet	     
rename  egotistical         egoistisch	      
rename  gentle              einfühlsam	    
rename  goodwithnums        gutmitZahle	   
rename  hardnosed           abgebrüht	    
rename  in_touch            bürgernah	   
rename  inspiring           inspirieren	
rename  intelligent         intelligent	  
rename  knowledgeable       sachkundig	        
rename  leader              führungsper	             
rename  liar                lügner		                     
rename  motherly            mütterlich	   
rename  motivated           motiviert	    
rename  nagging             nörgelend	  
rename  objective           objektiv	    
rename  organized           organisiert	
rename  powerhungry         machthungri	  
rename  quant               mathematisc	    
rename  rational            rational	           
rename  really_cares        sorgensichu	           
rename  rugged              robust		         
rename  scheming            intrigant	           
rename  self_interested     eigennützig	    
rename  sensitive           sensibel	          
rename  subordinates        unterwürfig	 
rename  smart               klug		             
rename  sneaky              hinterlisti	   
rename  stern               streng		              
rename  strongwilled        willensstar	 
rename  servile             aufopfernd	                
rename  tough               taff		      
rename  warm                warmherzig	     
rename  educated            gutgebildet	 
rename  whiny               weinerlich	              
rename  active              aktiv		       
rename  aggressive          aggressiv	   
rename  analytical          analytisch	   
rename  arrogant            arrogant	 
rename  bitter              verbittert	       
rename  boastful            überheblich	
rename  charismatic         charismatis	
rename  compassionate       mitfühlend	      
rename  competitive         ehrgeizig	    
rename  complaining         jammernd	    
rename  corrupt             korrupt		    
rename  daring              wagemutig	
rename  deceptive           betrügerisc	
rename  devious             hinterhälti	
rename  dictatorial         diktatorisc	
rename  dishonest           unehrlich	  
rename  dominant            dominant	 
rename  driven              getrieben	       
rename  emotional           emotional	  
rename  ethical             ethisch		
rename  fussy               kleinlich	      
rename  getsthingsdone      tatkräftig	       
rename  problemsolving      problemlösu	   
rename  greedy              gierig		
rename  gullible            leichtgläub	
rename  hardworking         fleißig		
rename  honest              ehrlich		   
rename  hostile             feindselig	
rename  imaginative         phantasievo	
rename  independent         unabhängig	    
rename  intuitive           intuitiv	  
rename  logical             logisch		
rename  loving              liebevoll	
rename  manipulative        manipulativ	 
rename  moral               integer		
rename  powerful            mächtig		
rename  quarrelsome         streitsücht	
rename  selfish             selbstsücht	
rename  sleazy              schmierig	
rename  spineless           rückgratlos	
rename  strong              stark		
rename  sympathetic         sympathisch	
rename  talkative           gesprächig	  
rename  separate_feelings   nichtinderl	      
rename  unemotional         unemotional	
rename  unprincipled        prinzipienl	 
rename  uptight             verklemmt	
rename  weak                schwach		
rename  wellspoken          wortgewandt	       


* Calculate leadership score 
foreach i of newlist _com _lea _emp _int {
	gen dk`i' = 0		
	foreach trait of global kinder`i' {
		replace dk`i' = dk`i' + 1 if `trait'==1
	}
}
* Calculate other scales
foreach i in newlist _agentic _communal _eaglyagen _eaglycomp {
	gen d`i' = 0		
	foreach trait of global d`i' {
		replace d`i' = d`i' + 1 if `trait'==1
	}
}

* Scale between 0 and 1
foreach var of varlist dk_* d_* {
	sum `var'
	replace `var' = `var' / r(max)
}

keep dk_* d_* group2

* copy vars so as to easily create SE in collapse command
foreach var of varlist dk_* d_* {
	gen se_`var' = `var'
	gen n_`var' = `var'
	rename `var' tot_`var'
}

* Summarize to means and standard errors
collapse (mean) tot_* (semean) se_* (count) n_*, by(group2)
drop if group2==3 | group2==6

* Reshape
reshape long tot_ se_ n_, j(trait) i(group2) string

gen target = ""
replace target = "fempol" if group2==2
replace target = "malpol" if group2==5
replace target = "allpol" if group2==7
replace target = "men"    if group2==4
replace target = "women"  if group2==1
drop group2

reshape wide tot_ se_ n_, i(trait) j(target) string

* Rename variables
foreach var of varlist tot_* {
	local tempname = regexr("`var'","tot_","") 
	rename `var' o_`tempname'_us
}
foreach var of varlist se_* n_* {
	rename `var' o_`var'_us
}

* Standardize scale variables
// Standardization of scale scores. The scale scores are standardized relative 
// to the mean trait percentages of all traits and groups, and the standard 
// deviation therein. The mean and standard deviation for this calculation are
// themselves calculated by putting the 99 trait percentages for each of the
// 5 social groups below each other, and taking the mean and sd.
* First, get the mean and standard deviation of trait percentages
preserve
	use "originalpercentages_US.dta", clear
	rename (o_women_us o_women_us_se o_fempol_us o_fempol_us_se o_men_us o_men_us_se o_malpol_us o_malpol_us_se o_allpol_us o_allpol_us_se) (o_us_women o_us_se_women o_us_fempol o_us_se_fempol o_us_men o_us_se_men o_us_malpol o_us_se_malpol o_us_allpol o_us_se_allpol)
	reshape long o_us_ , i(trait) j(group) string
	sum o_us_ if !regex(group,"se_") 
	global meantrait_o = r(mean)
	global sdtrait_o = r(sd)
	//reshape wide o_us_ , i(trait) j(group) string
	//rename (o_us_women o_us_se_women o_us_fempol o_us_se_fempol o_us_men o_us_se_men o_us_malpol o_us_se_malpol o_us_allpol o_us_se_allpol) (o_women_us o_women_us_se o_fempol_us o_fempol_us_se o_men_us o_men_us_se o_malpol_us o_malpol_us_se o_allpol_us o_allpol_us_se) 
restore

* Then create lower and upper bound variables
foreach group of newlist fempol allpol malpol men women {
	gen olb_`group'_us = o_`group'_us + o_se_`group'_us * invt(o_n_`group'_us,0.025)
	gen oub_`group'_us = o_`group'_us - o_se_`group'_us * invt(o_n_`group'_us,0.025)
}
//drop *_n_* *_se_*

* Standardize all
foreach var of varlist o_allpol* o_fempol* o_malpol* o_men* o_women* o*b_allpol* o*b_fempol* o*b_malpol* o*b_men* o*b_women* {
	gen `var'_std = (`var' - $meantrait_o) / $sdtrait_o
}
foreach var of varlist o_se_* {
	gen `var'_std = `var' / $sdtrait_o
}

* format numvers
format o* %3.2f

* Store
save "originalscalescores_US.dta", replace




